package toy.play.ssm.services;

import java.util.ArrayList;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import tool.Tools;
import toy.play.ssm.dao.KindsDAO;
import toy.play.ssm.model.Kinds;

@Service
public class KindsService {

	@Autowired
	private KindsDAO dao;

	public int addAKind(Kinds kinds)
	{
		kinds.setId(Tools.getUUID());
		kinds.setState(1);
		return dao.insert(kinds);
	}
	
	public int updateAKind(Kinds kinds)
	{
		return dao.update(kinds);
	}
	
	public int deleteAKind(Kinds kind)
	{
		kind.setState(0);
		return dao.update(kind);
	}
	
	public Kinds getAKindsById(String id)
	{
		return (Kinds)dao.getAObjectById(id);
	}
	
	public ArrayList<Kinds> getAllKindsInstate()
	{
		return (ArrayList<Kinds>) dao.getAllObject();
	}
	
	public ArrayList<Kinds> getSearch(String searchname)
	{
		ArrayList<Kinds> allkind=this.getAllKindsInstate();
		ArrayList<Kinds> somekind=new ArrayList<Kinds>();
		for(Kinds kind:allkind){
			
			if(kind.getName().contains(searchname))
			{
				somekind.add(kind);
			}
		}
		return somekind;
	}
}
